package com.yunxi.module.system.mapper.user;

import com.yunxi.framework.common.pojo.PageResult;
import com.yunxi.framework.mybatis.core.mapper.BaseMapperX;
import com.yunxi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yunxi.module.system.model.user.AdminUserDO;
import com.yunxi.module.system.vo.admin.user.user.UserPageReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 用户 mapper 接口
 * </p>
 *
 * @author lidy
 * @since 2024-05-08
 */
@Mapper
public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {

    /**
     * 根据用户账号查询用户信息
     *
     * @param username 用户账号
     * @return 用户信息
     */
    default AdminUserDO selectByUsername(String username) {
        return selectOne(AdminUserDO::getUsername, username);
    }

    /**
     * 根据邮箱账号查询用户
     *
     * @param email 邮箱账号
     * @return 用户信息
     */
    default AdminUserDO selectByEmail(String email) {
        return selectOne(AdminUserDO::getEmail, email);
    }

    /**
     * 根据手机号查询
     *
     * @param mobile 手机号
     * @return 用户信息
     */
    default AdminUserDO selectByMobile(String mobile) {
        return selectOne(AdminUserDO::getMobile, mobile);
    }

    /**
     * 分页查询用户列表
     *
     * @param pageReqVO 分页条件
     * @param deptIds   部门列表
     * @return 分页列表
     */
    default PageResult<AdminUserDO> selectPage(UserPageReqVO pageReqVO, Set<Long> deptIds) {
        return selectPage(pageReqVO, new LambdaQueryWrapperX<AdminUserDO>()
                .likeIfPresent(AdminUserDO::getUsername, pageReqVO.getUsername())
                .likeIfPresent(AdminUserDO::getMobile, pageReqVO.getMobile())
                .eqIfPresent(AdminUserDO::getStatus, pageReqVO.getStatus())
                .betweenIfPresent(AdminUserDO::getCreateTime, pageReqVO.getCreateTime())
                .inIfPresent(AdminUserDO::getDeptId, deptIds)
                .orderByDesc(AdminUserDO::getId));
    }

    /**
     * 获得制定状态的用户集合
     *
     * @param status 状态
     * @return 用户集合
     */
    default List<AdminUserDO> selectUserListByStatus(Integer status) {
        return selectList(AdminUserDO::getStatus, status);
    }
}
